package kit.edu.lego.gruppe3.levels.line;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.levels.bridge.BridgeSolver;
import kit.edu.lego.gruppe3.levels.door.DoorSolver;
import kit.edu.lego.gruppe3.levels.labyrinth.LabyrinthSolver;
import kit.edu.lego.gruppe3.levels.rollbridge.RollBridgeSolver;
import kit.edu.lego.gruppe3.levels.sumpf.SumpfSolver;
import kit.edu.lego.gruppe3.levels.treeArea.TreeAreaSolver;
import lejos.nxt.LightSensor;
import lejos.robotics.subsumption.*;
import kit.edu.lego.gruppe3.sensors.*;

public class LineSolver implements LevelSolver
{

	private static int state= -1;

	
	LightSensor lightSensor = ComponentsRepository.getInstance().getLightSensor();
	public LineSolver()
	{

	}
	
	
	public void start()
	{

		LineSolver.incState();
		finishPreviousLevels();
		Scanner.getRangeAt(0,true);
		LevelSelector.getInstance().setCurrentLevel(Level.line);
		
		Behavior findObstacle = new findObstacle(); 
		Behavior followObstacle = new followObstacle();
		Behavior lineEnd = new LineEndReached();
		Behavior followLine = new LineFollower();
		Behavior lineFinder = new LineFinder();
		Behavior lineObstacle = new LineObstacle();
		Behavior rotateBridge = new RotateBridge();
		
		Behavior[] behaviors = {followLine, lineFinder, lineObstacle, followObstacle, findObstacle, lineEnd, rotateBridge};
		Arbitrator arby = new Arbitrator(behaviors, true);
		
		arby.start();
	}
	
	
	private void finishPreviousLevels() {
		LabyrinthSolver.setLevelCleared(true);
		SumpfSolver.setLevelCleared(true);
	}
	
	public static int incState(){
		return ++state;
	}
	
	public static int getState(){
		return state;
	}
	@Override
	public String toString() {
		return "Line solver";
	}

}
